Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【igl nanovg part-1】shell | mac | add stencil buffer #216

Conversation

vinsentli
Copy link
Contributor

This is a prerequisite pull request for igl nanovg(#213).

@vinsentli vinsentli changed the title shell | mac | add stencil buffer 【igl nanovg part-1】shell | mac | add stencil buffer Nov 26, 2024
Copy link
Contributor

@corporateshark corporateshark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make it configurable, with the default setting matching the previous behavior. No stencil buffer should be enabled by default unless requested explicitly.

@vinsentli
Copy link
Contributor Author

Please make it configurable, with the default setting matching the previous behavior. No stencil buffer should be enabled by default unless requested explicitly.

done

@@ -196,6 +196,10 @@ - (void)loadView {

#if IGL_BACKEND_OPENGL
case igl::BackendFlavor::OpenGL: {
bool enableStencilBuffer = config_.depthTextureFormat == igl::TextureFormat::S8_UInt_Z24_UNorm ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@corporateshark corporateshark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default behavior should be to keep the stencil buffer disabled.

@@ -109,6 +109,7 @@ - (void)setupViewController {
.majorVersion = 3,
.minorVersion = 0},
.swapchainColorTextureFormat = kColorFramebufferFormat,
.depthTextureFormat = igl::TextureFormat::S8_UInt_Z24_UNorm,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not ne changed for all apps. Only apps using NanoVG would want to enable the stencil buffer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line still stands. We should not enable the stencil buffer unconditionally for all apps.

@vinsentli
Copy link
Contributor Author

I have moved the depth texture format configuration into RenderSession.
And iOS has create a new PR #221 base on this PR.

@facebook-github-bot
Copy link
Contributor

@corporateshark has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@@ -16,7 +16,6 @@ struct RenderSessionConfig {
std::string displayName;
BackendVersion backendVersion;
igl::TextureFormat swapchainColorTextureFormat = igl::TextureFormat::BGRA_UNorm8;
igl::TextureFormat depthTextureFormat = igl::TextureFormat::Z_UNorm16;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of our internal code that relies on this field. Is it possible to add stencil buffer support without getting rid of it?

Copy link
Contributor Author

@vinsentli vinsentli Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field depthTextureFormat is add by me in this commit.49d674c

This PR revert the commit before, add move the depthTextureFormat field into RenderSession.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field depthTextureFormat is add by me in this commit.49d674c

I looked into it, the tests do not pass because the file shell/ios/ViewController.mm needs to be updated as well. It still uses depthTextureFormat.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed iOS compile error.

The complete adaptation of the iOS stencil buffer is another PR(#221).
It should be merged with the latest main branch and reviewed after this PR is approved.

@facebook-github-bot
Copy link
Contributor

@corporateshark has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@corporateshark corporateshark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mixing changes to the mac shell with changes to the iOS shell.

@@ -42,7 +42,6 @@ - (BOOL)application:(UIApplication*)application
.majorVersion = 3,
.minorVersion = 0},
.swapchainColorTextureFormat = igl::TextureFormat::BGRA_SRGB,
.depthTextureFormat = igl::TextureFormat::S8_UInt_Z32_UNorm,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a good change. What compilation failure is this fixing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved the depthTextureFormat field from RenderSessionConfig to RenderSession, so the above code must be removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to achieve your goal (adding NanoVG) with minimal changes to the current main branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make the minimal changes as much as possible.

@@ -45,6 +49,10 @@ class RenderSession {
void setCurrentQuadLayer(size_t layer) noexcept {
currentQuadLayer_ = layer;
}

[[nodiscard]] igl::TextureFormat getDepthTextureFormat() const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this addition? The point of suggested+requested configs is to let a particular session choose the formats it wants without needing to create some kind of dummy session without a platform.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want the stencil buffer to be disabled by default. So, I can only move the depthTextureFormat field from RenderSessionConfig to RenderSession, and then NanovgRenderSession can override the default depthTextureFormat.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything already merged into main is fine. For any further changes, aim to make only the minimal changes necessary. Please update your diffs to minimize the modifications required to add NanoVG.

Copy link
Contributor Author

@vinsentli vinsentli Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The minimal way to make the changes is to keep the depthTextureFormat field in RenderSessionConfig.

If I want to show the NanoVG session and make changes to depthTextureFormat locally, and avoid committing it to the main branch.

I can add comments in NanovgSession to explain that other developers can make such changes if they want to show the effect.

This approach is also well-suited for Android, because without it, the changes required for Android would be significant as well.

What do you think about this approach?

@vinsentli
Copy link
Contributor Author

vinsentli commented Dec 10, 2024

This is the minimal changes.
iOS is currently appropriate, and no further modifications are needed.

I made modifications to depthTextureFormat in mac/AppDelegate.mm. If you think this is not appropriate, I can revert those changes.

@facebook-github-bot
Copy link
Contributor

@corporateshark has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@@ -109,6 +109,7 @@ - (void)setupViewController {
.majorVersion = 3,
.minorVersion = 0},
.swapchainColorTextureFormat = kColorFramebufferFormat,
.depthTextureFormat = igl::TextureFormat::S8_UInt_Z24_UNorm,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line still stands. We should not enable the stencil buffer unconditionally for all apps.

@@ -196,6 +196,10 @@ - (void)loadView {

#if IGL_BACKEND_OPENGL
case igl::BackendFlavor::OpenGL: {
const bool enableStencilBuffer = config_.depthTextureFormat == igl::TextureFormat::S8_UInt_Z24_UNorm ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you extract all these changes in shell/mac/ViewController.mm into a separate PR, it will be easier to review and merge because it does not change any existing behaviors.

@corporateshark
Copy link
Contributor

Ok, I'm landing the shell/mac/ViewController.mm part of this PR. The AppDelegate.mm part should be reimplemented to keep the existing default depth format.

@facebook-github-bot
Copy link
Contributor

@corporateshark merged this pull request in 88143c1.

@vinsentli vinsentli deleted the igl_nanovg_part1_mac_add_stencil_buffer branch December 18, 2024 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants